<!--
  消息推送-学生用户
 -->
<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="认证状态" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="请选择学生状态"
          clearable
          size="small"
        >
          <el-option label="已认证" value="1" />
          <el-option label="未认证" value="2" />
        </el-select>
      </el-form-item>
      <el-form-item label="姓名" prop="studentName">
        <el-input
          v-model="queryParams.studentName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="handleQuery"
        >搜索</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table ref="studentTable" v-loading="loading" :row-key="getRowKey" :data="list" @selection-change="handleChange">
      <el-table-column
        type="selection"
        width="55"
        :reserve-selection="true"
      />
      <el-table-column label="用户名" align="center" prop="nickname" />
      <el-table-column label="手机号" align="center" prop="mobile" />
      <el-table-column label="认证状态" align="center" prop="status">
        <template slot-scope="scope">{{
          Number(scope.row.status) === 1 ? "已认证" : "未认证"
        }}</template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page-sizes="[10, 20, 30, 50, 100]"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  getStudentPage
} from '@/api/school-admin-api/userManage/student/index.js'
import { deepClone } from '@/utils/index'

export default {
  name: 'StudentList',
  components: {
  },
  data() {
    return {
      selectSdudentList: [],
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 企业管理列表
      list: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        studentName: null,
        mobile: null,
        status: null
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getRowKey(row) {
      return 'student' + row.id
    },
    // 多选
    handleChange(val) {
      console.log('选中学生>>>', val)
      this.selectSdudentList = [...val]
      this.$emit('selectChange', [...this.selectSdudentList])
    },
    deleteSelectionItem(item) {
      this.$refs.studentTable.toggleRowSelection(item, false)
      console.log('删除选中>>>', item)
    },
    /** 查询列表 */
    getList() {
      this.loading = true
      // 处理查询参数
      const params = deepClone(this.queryParams)
      // status 1 认证 2 未认证
      // 0 默认状态， 1 认证通过， 2 认证驳回 3 认证中
      if (Number(params.status) === 1) {
        params.status = [1]
      } else if (Number(params.status) === 2) {
        params.status = [0, 2, 3]
      }
      for (const key in params) {
        if (params[key] === null || params[key] === '') {
          delete params[key]
        }
      }
      // 执行查询
      getStudentPage(params).then((response) => {
        this.list = response.data.list
        this.total = response.data.total
        this.loading = false
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.selectSdudentList = []
      this.resetForm('queryForm')
      this.$refs.studentTable.clearSelection()
      this.handleQuery()
    }
  }
}
</script>

